layui.use(['table'], function () {
    var $ = layui.$,
        table = layui.table;

    var logtable = table.render({
        elem: '#log_table',
        url: '/standard/getStandardLog',
        page: true,
        limits: [10, 20, 30],
        height: 400,
        cols: [
            [
                {
                    field: '', title: '序号', fixed: 'left', width: 80, align: 'center', templet: function (d) {
                        return d.LAY_INDEX
                    }
                },
                {field: 'module', title: '操作备注',},
                {
                    field: 'state', title: '操作状态', templet(d) {
                        if (d.state == '200') {
                            return `<span style="color: #5FB878">成功</span>`
                        } else {
                            return `<span style="color: #ff0000">失败</span>`
                        }
                    }
                },
                {
                    field: 'type', title: '类型', width: 200, templet(d) {
                        if (d.type == '1') {
                            return `<span>增加</span>`
                        } else if (d.type == '2') {
                            return `<span>删除</span>`
                        } else if (d.type == '3') {
                            return `<span>修改</span>`
                        } else if (d.type == '4') {
                            return `<span>查询</span>`
                        }
                    }
                },
                {field: 'operationTime', sort: true, title: '操作时间',},
                {field: '', title: '操作', toolbar: '#tool'}
            ]
        ],
        toolbar: true,
        parseData: function (res) {
            console.log(res)
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.count, //解析数据长度
                "data": res.data //解析数据列表
            };
        }
    })

    table.on('tool(log_table)', function (obj) {
        console.log(obj)
        if (obj.event === 'del') {
            layer.confirm('确认删除该条日志吗？', function () {
                console.log('确认')
                $.get({
                    url: '/standard/delStandardLog',
                    data: {id: obj.data.id},
                    dataType: 'json',
                    success: res => {
                        if (res.state == '200') {
                            layer.msg('删除成功')
                            logtable.reload()
                        } else {
                            layer.msg('删除失败')
                        }
                    }
                })
            })
        }
    })
})
